/**
 * 
 */
package com.game.sessionPool;

import java.util.HashMap;
import java.util.Map;
import org.apache.mina.core.session.IoSession;

/**
 * @author lushouzhi
 *
 */
public class DefaultSessionPool implements SessionPool{
	
	private Map<Integer,IoSession> sessionPool=new HashMap<Integer, IoSession>();
	@Override
	public void add(int uid, IoSession session) {
		if(sessionPool.containsKey(uid)){
			close(uid, true);
			remove(uid);
		}
		sessionPool.put(uid, session);
	}

	@Override
	public IoSession get(int uid) {
		return sessionPool.get(uid);
	}

	@Override
	public void remove(int uid) {
		sessionPool.remove(uid);
	}

	@Override
	public void close(int uid,boolean flag) {
		IoSession session=get(uid);
		if(session!=null){
			session.close(flag);
		}
	}
}
